Ccay.Module
		.define(
				"Ccay.example.functionDemo.excel",
				function(page, $S) {
					page.chkName = "";
					/**
					 * Grid初始化
					 */
					page.ready = function() {
						$("#demoImport").ccayTab();
						var gridOptions = {
							columns : [ {
								id : '',
								isCheckColumn : true,
								frozen : true,
								align : "center"
							}, {
								id : 'name',
								header : "ccay.demoImport.label.name",
								editable : false
							}, {
								id : 'displayName',
								header : "ccay.demoImport.label.displayname"
							}, {
								id : 'language',
								header : "ccay.demoImport.label.language",
								align : "center",
								width : 60
							}, {
								id : 'description',
								header : "ccay.demoImport.label.description"
							}, {
								id : 'value',
								header : "value"
							}, {
								id : 'attributeOne',
								header : "attr1"
							}, {
								id : 'attributeTwo',
								header : "attr2"
							}, {
								id : 'attributeThree',
								header : "attr3"
							}, {
								id : 'attributeFour',
								header : "attr4"
							}, {
								id : 'attributeFive',
								header : "attr5"
							}, {
								id : 'attributeSix',
								header : "attr6"
							}, {
								id : 'attributeSeven',
								header : "attr7"
							}, {
								id : 'attributeEight',
								header : "attr8"
							}, {
								id : 'attributeNine',
								header : "attr9"
							}, {
								id : 'attributeTen',
								header : "attr10"
							} ],
							operation : {
								search : {
									btn : '#btnSearch',
									panel : '#demoImportForm',
									url : 'services/ccay/example/demoImport/list/page/{0}/{1}'
								}
							}
						};
						$S("#demoImportGrid").ccayGrid(gridOptions);
						var igridOption = {
							height : 200,
							wrap : true,
							customSetting : true,
							columns : [ {
								columnType : 'select',
								multi : true
							}, {
								field : 'name',
								width : 90,
								header : "ccay.demoImport.label.name",
								editable : false
							}, {
								field : 'displayName',
								width : 150,
								header : "ccay.demoImport.label.displayname"
							}, {
								field : 'language',
								header : "ccay.demoImport.label.language",
								align : "center",
								width : 60
							}, {
								field : 'description',
								width : 90,
								header : "ccay.demoImport.label.description"
							}, {
								field : 'value',
								width : 90,
								header : "value"
							}, {
								field : 'attributeOne',
								width : 40,
								header : "attr1"
							}, {
								field : 'attributeTwo',
								width : 40,
								header : "attr2"
							}, {
								field : 'attributeThree',
								width : 40,
								header : "attr3"
							}, {
								field : 'attributeFour',
								width : 40,
								header : "attr4"
							}, {
								field : 'attributeFive',
								width : 40,
								header : "attr5"
							}, {
								field : 'attributeSix',
								width : 40,
								header : "attr6"
							}, {
								field : 'attributeSeven',
								width : 40,
								header : "attr7"
							}, {
								field : 'attributeEight',
								width : 40,
								header : "attr8"
							}, {
								field : 'attributeNine',
								width : 40,
								header : "attr9"
							}, {
								field : 'attributeTen',
								width : 40,
								header : "attr10"
							} ],
							ajax : {
								url : 'services/ccay/example/demoImport/list/page/{0}/{1}'

							}
						};

						// 点击tab头后，才加载数据，只第一次生效demo2
						$S("li[tabid='_tabitem2']").one("click", function() {
							$S("#demoImportGrid1").igrid(igridOption);
						});
					};

					page.DemoImport = function() {
						var errorDisplay = $S("#dynamic_error_id").val();
						var param = {
							uploadType : "ExcelImport",
							completeCallback : Ccay.Component.Excel.uploadCallback,
							callback : Ccay.example.functionDemo.excel.uploadCallback2,
							closeDialog : true,
							query : "excelType=ccay.example&errorDisplay="
									+ errorDisplay + getUrl()
						};
						// &processBefore=demoImportProcessBefore
						Ccay.Component.openUploadDialog("Demo Import", param);
					}
					page.uploadCallback2 = function(file, serverData, batchId,
							userObject) {

					}
					page.DemoSyncImport = function() {

						var param = {
							uploadType : "ExcelSyncImport",
							callback : Ccay.example.functionDemo.excel.uploadCallback,
							closeDialog : true,
							query : "excelType=ccay.exampleSync"
						};
						Ccay.Component.openUploadDialog("Demo Import", param);
					}
					page.uploadCallback = function(file, serverData, batchId,
							userObject) {
						if (serverData && serverData.length > 0) {
							$S("#demoSyncImportData").html("");// 清空内容
							var list = "<ul>";
							for (var i = 0; i < serverData.length; i++) {
								list += "<li>{0}--{1}--{2}--{3}</li>"
										.formatValue(serverData[i].name,
												serverData[i].displayName,
												serverData[i].language,
												serverData[i].description);
							}
							list += "</ul>";
							$S("#demoSyncImportData").html(list);
						}

					}

					/**
					 * grid动态列的数据
					 */
					zuzhuangshuj = function() {
						var data = {};
						var parentPath = $S("#dynamic_p_id").val();
						var value = $S("#dynamic_chk_id_0")[0].checked;
						var attributeOne = $S("#dynamic_chk_id_1")[0].checked;
						var attributeTwo = $S("#dynamic_chk_id_2")[0].checked;
						var attributeThree = $S("#dynamic_chk_id_3")[0].checked;
						var attributeFour = $S("#dynamic_chk_id_4")[0].checked;
						var attributeFive = $S("#dynamic_chk_id_5")[0].checked;
						var attributeSix = $S("#dynamic_chk_id_6")[0].checked;
						var attributeSeven = $S("#dynamic_chk_id_7")[0].checked;
						var attributeEight = $S("#dynamic_chk_id_8")[0].checked;
						var attributeNine = $S("#dynamic_chk_id_9")[0].checked;
						var attributeTen = $S("#dynamic_chk_id_10")[0].checked;
						if (parentPath.length > 0) {
							data['parentPath'] = parentPath;
						}
						if (value) {
							data['value'] = '1';
						}
						if (attributeOne) {
							data['attributeOne'] = '1';
						}
						if (attributeTwo) {
							data['attributeTwo'] = '1';
						}
						if (attributeThree) {
							data['attributeThree'] = '1';
						}
						if (attributeFour) {
							data['attributeFour'] = '1';
						}
						if (attributeFive) {
							data['attributeFive'] = '1';
						}
						if (attributeSix) {
							data['attributeSix'] = '1';
						}
						if (attributeSeven) {
							data['attributeSeven'] = '1';
						}
						if (attributeEight) {
							data['attributeEight'] = '1';
						}
						if (attributeNine) {
							data['attributeNine'] = '1';
						}
						if (attributeTen) {
							data['attributeTen'] = '1';
						}
						return data;
					}
					/**
					 * grid显示列的数据
					 */
					gridcolumndatas = function() {
						var grid = $("#demoImportGrid").getCcayGridManager();
						var hList = [];
						$.each(grid.columnList, function(i, c) {
							// 把gird显示列信息加入 hList
							!c.hidden && hList.push(c);
						})

						var data = {};
						// 获取自动义的excel filename前缀
						var parentPath = $S("#dynamic_p_id").val();
						if (parentPath.length > 0) {
							data['parentPath'] = parentPath;
						}
						for (var i = 0; i < hList.length; i++) {
							// 把要导出的列属性设定一个默认的值1,json然后放到data{};
							data[hList[i].id] = '1';
						}
						return data;
					}
					/**
					 * igrid显示列的数据
					 */
					igridcolumndatas = function() {
						var igrid = $("#demoImportGrid1").manager();
						var hList = [];
						$.each(igrid.op.columns, function(i, c) {
							// 把igird显示列信息加入 hList
							(c.hidden == undefined || !c.hidden)
									&& hList.push(c);
						})

						var data = {};
						for (var i = 0; i < hList.length; i++) {
							// 把要导出的列属性设定一个默认的值1,json然后放到data{};
							if(hList[i].field != undefined){
								data[hList[i].field]='1';
							}
						}
						return data;
					}

					page.demoExport = function() {
						Ccay
								.doGet(
										"services/ccay/example/demoExport/list/export",
										zuzhuangshuj(), function() {
											Ccay.Component.Excel
													.exportCallback();
										});
					}

					page.griddemoExport = function() {
						Ccay
								.doGet(
										"services/ccay/example/demoExport/dynamiclist/export",
										gridcolumndatas(), function() {
											Ccay.Component.Excel
													.exportCallback();
										});
					}

					page.igriddemoExport = function() {
						Ccay
								.doGet(
										"services/ccay/example/demoExport/dynamiclist/export",
										igridcolumndatas(), function() {
											Ccay.Component.Excel
													.exportCallback();
										});
					}
					page.resultIexcelExport = function() {
						data = zuzhuangshuj();
						Ccay
								.doGet(
										"services/ccay/example/demoExport/list/export/iexcel",
										data, function() {
											Ccay.Component.Excel
													.exportCallback();
										});
					}

					page.resultSetExport = function() {
						data = zuzhuangshuj();
						data['name'] = 'resultSet';
						Ccay
								.doGet(
										"services/ccay/example/demoExport/list/export",
										data, function() {
											Ccay.Component.Excel
													.exportCallback();
										});
					}

					/**
					 * 动态模板列复选框单击事件初始化
					 */
					page.chkSelect = function(chkAllObj) {
						if (chkAllObj.checked) {
							$S("#" + chkAllObj.id + " :checkbox:enabled").attr(
									"checked", true);
							page.chkName = $S("#" + chkAllObj.id).getValue();
						} else {
							$S("#" + chkAllObj.id + " :checkbox:enabled").attr(
									"checked", false);
							page.chkName = "";
						}
					};
					/**
					 * 动态模板下载
					 */
					page.demoDynamicExcelTemplate = function() {

						location.href = "servlet/download?dlType=ExcelTemplate&excelType=ccay.example"
								+ getUrl();
					};
					getUrl = function() {
						var subb = '';
						var value = $S("#dynamic_chk_id_0")[0].checked;
						var errorDisplay = $S("#dynamic_error_id").val();
						var attributeOne = $S("#dynamic_chk_id_1")[0].checked;
						var attributeTwo = $S("#dynamic_chk_id_2")[0].checked;
						var attributeThree = $S("#dynamic_chk_id_3")[0].checked;
						var attributeFour = $S("#dynamic_chk_id_4")[0].checked;
						var attributeFive = $S("#dynamic_chk_id_5")[0].checked;
						var attributeSix = $S("#dynamic_chk_id_6")[0].checked;
						var attributeSeven = $S("#dynamic_chk_id_7")[0].checked;
						var attributeEight = $S("#dynamic_chk_id_8")[0].checked;
						var attributeNine = $S("#dynamic_chk_id_9")[0].checked;
						var attributeTen = $S("#dynamic_chk_id_10")[0].checked;
						if (value) {
							subb += "&value=1";
						}
						if (attributeOne) {
							subb += "&attributeOne=1";
						}
						if (attributeTwo) {
							subb += "&attributeTwo=1";
						}
						if (attributeThree) {
							subb += "&attributeThree=1";
						}
						if (attributeFour) {
							subb += "&attributeFour=1";
						}
						if (attributeFive) {
							subb += "&attributeFive=1";
						}
						if (attributeSix) {
							subb += "&attributeSix=1";
						}
						if (attributeSeven) {
							subb += "&attributeSeven=1";
						}
						if (attributeEight) {
							subb += "&attributeEight=1";
						}
						if (attributeNine) {
							subb += "&attributeNine=1";
						}
						if (attributeTen) {
							subb += "&attributeTen=1";
						}
						subb += "&errorDisplay=" + errorDisplay;
						return subb;
					}
					page.demoExcelTemplate = function() {
						location.href = "servlet/download?dlType=ExcelTemplate&excelType=ccay.example"
								+ getUrl();
					}
				});